-- guid, spell, time
tblDebuff = {}

function ccrCastDebuff(spell, unit)
	if unit == nil then unit = "target" end
	if tonumber(spell) ~= nil then spell = SpellIDToName(spell) end

	if ccrValidTarget(unit)
	and SpellCanAttack(spell, unit)
	then
		local vReApplyDebuff
		-- Check for previous attempt, if so return
		if # tblDebuff > 0 then
			for i = 0, # tblDebuff do
				if tblDebuff[i] ~= nil then
					vGUID, vSpell, vTime = strsplit(",", tblDebuff[i]);
					if UnitGUID(unit) == vGUID
					and vSpell == spell
					then
						vTravelTime = (((ccrDistance("player", unit) / 5) * (1000/3))/1000)
						if (GetTime()-vTime) > vTravelTime then
							vReApplyDebuff = true
							table.remove(tblDebuff, i)
						else
							return
						end
					end
				end
			end
		end
		-- Cast the Debuff
		if vReApplyDebuff == nil or vReApplyDebuff == true then
			local vEndOfSpellCast = GetTime()+((select(7,GetSpellInfo(spell)))/1000)+0.3
			ccrCastAttack(spell, unit);
			if ccrPlayerIsCastingOrChanneling() then
				table.insert(tblDebuff, UnitGUID(unit) .. "," .. spell .. "," .. vEndOfSpellCast);
			end
		end

	end
end
